﻿using Microsoft.AspNetCore.Identity;
using Newtonsoft.Json;
using System.Security.Principal;
using System.Xml.Serialization;

namespace MiniFox.Platform
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable, JsonObject]
    public abstract class SystemIdentity : IIdentity
    {
        string _globalId;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="globalId"></param>
        public SystemIdentity(string globalId)
        {
            _globalId = globalId;
        }
        /// <summary>
        /// 全局唯一身份ID
        /// </summary>
        [JsonProperty("globalId")]
        public virtual string GlobalID
        {
            get { return this._globalId; }
        }
        /// <summary>
        /// 显示名，如：昵称、姓名或应用程序显示名
        /// </summary>
        public string DisplayName
        {
            get;
            set;
        }
        /// <summary>
        /// 转换为string对象，默认返回全局唯一身份ID
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (_globalId == null)
                return null;
            return this._globalId.ToString();
        }
        /// <summary>
        /// 全局唯一登录名
        /// </summary>
        [JsonProperty("name")]
        public virtual string Name
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore, XmlIgnore]
        public abstract string AuthenticationType
        {
            get;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore, XmlIgnore]
        public virtual bool IsAuthenticated
        {
            get
            {
                return true;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("roles")]
        public string[] Roles { get; set; }
    }
}
